public class Client extends Thread
{
    public static Shop shop;
    public static int totalClients = 0;

    public Client(Shop shop)
    {
        this.shop = shop;
    }

    public void run()
    {
        try {
            this.sleep((int) (Math.random() * 100 + 100));
        } catch (InterruptedException exc) {
            exc.printStackTrace();
            System.exit(1);
        }
        totalClients += 1;
        System.out.println(this.getId() + " quiere entrar");

        synchronized (shop)
        {
            while (shop.clientCounter >= 10)
            {
                try {
                    shop.wait();
                } catch (Exception exc)
                {
                    exc.printStackTrace();
                    System.exit(1);
                }
            }
        }
        shop.enter();
        System.out.println(shop.clientCounter + " en la tienda");
        try {
            this.sleep((int) (Math.random() * 2 + 1) * 1000);
        } catch (InterruptedException exc) {
            exc.printStackTrace();
            System.exit(1);
        }
        shop.leave();
        System.out.println(this.getId() + " ha salido");
    }
}
